package com.chapter16.Homework;

import java.util.Scanner;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) {
        C1 c1 = new C1();
        C2 c2 = new C2(c1);
        Thread thread = new Thread(c1);
        thread.setDaemon(true);
        thread.start();
        new Thread(c2).start();
    }
}

class C1 implements Runnable {
    private  boolean loop = true;

    @Override
    public void run() {
        while (loop) {
            System.out.println((int) (Math.random() * 100 + 1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}

class C2 implements Runnable{
    private C1 c1;
    public Scanner scanner = new Scanner(System.in);

    public C2(C1 c1) {
        this.c1 = c1;
    }

    @Override
    public void run() {
        while (true) {
            System.out.print("请输入你的指令:");
            char c = scanner.next().toUpperCase().charAt(0);
            if (c == 'Q') {
//                c1.setLoop(false);
                break;
            }
        }
    }
}
